<?
class Connection extends Root{
	var $Session;		//Objet contenant la session PHP
	var $Num;		//Num de la connexion
	var $Date;		//Date de la connexion
	var $Ip;		//Ip de la connexio
	var $Host;		//Nom de l hote
	var $NavLang;		//Langue de l hote
	var $Navigateur;	//Type du navigateur
	var $Id;		//Id de connexion
	var $Ref;
	var $Record;
	var $SessId="";
	var $login;
	var $pass;
	var $passmd5;
	var $codeverif;

	//------------------------------------------------------------//
	//			CONSTRUCTEUR			      //
	//------------------------------------------------------------//
	//C est ici que l on configure la connexion et que l on définit les processus d identification


       /**
         * Recherche parmi les variables disponibles si il y a un KESESSID. Si oui, renvoie vrai et affecte Sessid
         *
         * @return boolean
         */function hasSessid() {
             $sessid = "";
             if ( $_COOKIE[PHP_SESSION_NAME] ) $sessid = $_COOKIE[PHP_SESSION_NAME] ;
             elseif ( $_GET[PHP_SESSION_NAME] ) $sessid = $_GET[PHP_SESSION_NAME];
             elseif ( $_POST[PHP_SESSION_NAME] ) $sessid = $_POST[PHP_SESSION_NAME];
             if ( $sessid != "" ) {
                 $this->Sessid = $sessid;
                 return true;
             }else {
                 return false;
             }
         }
        
	function Connection() {
		//RECUPERATION DE LA CONNEXION 
		$this->GetConn();
		if ($this->hasSessid()) {
                    $this->DemarreSession();
                    if (!$this->ChargementSessionVars())
                      $this->LoadLoginVars();
                    if (!$this->DetectUser()) $this->initDefaultUser();
		}elseif($_COOKIE["PHPSESSID"]!=""){
                    //Utilisateur public
                    $this->initPublicSession();
                    $this->LoadLoginVars();
                    if (!$this->DetectUser()){
                        $this->initDefaultUser();
                    }else{
                        //Il faut basculer les informations de la session
                        $this->SessionPublicToPrivate();
                    }
                }elseif ( !empty($_COOKIE) ) {
                    //Chargement des variables des Cookies
                    $this->LoadLoginVars();
                    if (!$this->DetectUser()){
                        $this->initDefaultUser();
                    }else{
                        //On genere l id de session
                        $_COOKIE=Array();
                        $this->SessId = $this->genSessId($this->login,$this->pass,$GLOBALS["Systeme"]->User->Id);
                        //Creation Session
                        $this->DemarreSession();
                        //Enregistrement des variable
                        $this->SaveSessionVars();
                        header("Location: http://".$_SERVER["HTTP_HOST"]."/".$GLOBALS["Systeme"]->getPostVars("goto"));
                    }                    
		}else{
                    $this->LoadLoginVars();
                    if ($this->DetectUser()) {
                        //On genere l id de session
                          $this->SessId = $this->genSessId($this->login,$this->pass,$GLOBALS["Systeme"]->User->Id);
                        //Creation Session
                          $this->DemarreSession();
                        //Enregistrement des variable
                          $this->SaveSessionVars();
                    }else{
                        $this->initDefaultUser();
                    }       
		}
		//Creation de la connexion
		$this->AddConn();
	}

	//------------------------------------------------------------//
	//			SESSION PHP			      //
	//------------------------------------------------------------//

	function SaveSessionVars() {
		$this->addSessionVar("login",$this->login);
		if (is_null($this->passmd5)) $this->addSessionVar("pass",$this->pass);
		else $this->addSessionVar("pass",$this->passmd5);
		$this->addSessionVar("UserCache",serialize($GLOBALS["Systeme"]->User));
                
	}

	function ChargementSessionVars() {
            $this->login = $_SESSION["login"];
            $this->pass = $_SESSION["pass"];
            if (!is_null($_SESSION["UserCache"])){
                $GLOBALS["Systeme"]->User = unserialize($_SESSION["UserCache"]);
            }
            foreach ($_SESSION as $Key=>$Value){
                $sendVar = $Value;
                if (is_object(unserialize($Value))||is_array(unserialize($Value)))
                  $sendVar = unserialize($Value);
                $GLOBALS["Systeme"]->RegisterVar($Key,$sendVar);
            }
            return true;
	}

	function initPublicSession() {
            session_start();
            $this->ChargementSessionVars();
	}

	function SessionPublicToPrivate() {
		//echo "On bascule la session publique par la priv�e";
		session_start();
		$OldSession = $_SESSION;
		if (isset($_COOKIE[session_name()])) {
			setcookie(session_name(), '', time()-42000, '/');
		}
		session_destroy();
		setcookie ("PHPSESSID", "", time()-60000);
		$this->SessId = $this->genSessId($this->login,$this->pass,$GLOBALS["Systeme"]->User->Id);
		//Creation Session
		$this->DemarreSession();
		$_SESSION = $OldSession;
		$this->SaveSessionVars();
	}

	function configSession($Id) {
		session_set_cookie_params  (864000000);
		//Configuration de la session
		if ($Id==NULL) die("Utilisateur incorrect.");
		session_name(PHP_SESSION_NAME);
		//Emplacement de sauvegarde du fichier de session
		$Path = $_SERVER["DOCUMENT_ROOT"]."/Home/".$Id."/.sessions";
		if (!file_exists($Path)) $this->mk_dir($Path,0755);
		session_save_path($Path);
	}

	function genSessId($login,$pass,$id) {
		$temp = md5($login."-".$pass);
		$temp = "dddd".$id."dddd".$temp;
		$sessid = $temp;
		session_id($sessid);
		return $sessid;
	}

	function extractSessId() {
		$temp = explode("dddd",$this->SessId);
		$Id = $temp[1];
		return $Id;
	}

	function destroyPrivateSession() {
		$GLOBALS["Systeme"]->isLogged=0;
		session_start();
		$_SESSION = array();
		if (isset($_COOKIE[session_name()])) {
			setcookie(session_name(), '', time()-42000, '/');
		}
		session_destroy();
		setcookie (PHP_SESSION_NAME, "", time()-60000);
		//SUppression de la connexion
		if (ADD_CONNECT){
			$query="Systeme/Connexion/Session=".$this->SessId."&Navigateur=".addslashes($this->Navigateur)."&Ip=".$this->Ip."&tmsEdit>".(time()-(CONNECT_TIMEOUT*60));
			$Result = $GLOBALS["Systeme"]->Modules["Systeme"]->callData($query);
			$Connexion = genericClass::createInstance("Systeme",$Result[0]);
			$Connexion->Delete();
		}
		//if ($GLOBALS["Systeme"]->getPostVars("goto")!="") header("Location:".$GLOBALS["Systeme"]->getPostVars("goto")."?msg=notlogged");
		//else header("Location: http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]);
		return true;
	}

	function DemarreSession() {
		//On recupere le numero de la session dans le cookie
		$Id = $this->extractSessId();
		//On verifie que le fichier de session existe
/*		if (!file_exists("Home/$Id/.sessions/".$this->SessId)){
			//Destruction du cookie
// 			echo "DESTRUCTION SESSION";
			$this->destroyPrivateSession();
		}*/
		//On configure le systeme de session
		$this->configSession($Id);
		session_start();
	}

	function addSessionVar($Nom,$Valeur){
	//Rajoute une variable a la session
		//echo "ENREGISTREMENT DE VARIABLE $Nom $Valeur";
		session_register($Nom);
		$_SESSION[$Nom] = $Valeur;
		$GLOBALS["Systeme"]->RegisterVar($Nom,$Valeur);
	}

	function rmSessionVar($Nom) {
		unset($_SESSION[$Nom]);
	}
	//------------------------------------------------------------//
	//			VARIABLES KOB-EYE		      //
	//------------------------------------------------------------//
	function Connect($Login,$Pass){
		$this->login = $Login;
		$this->pass = md5($Pass);
                if ($this->DetectUser() )
                  {
		      $this->SessionPublicToPrivate();
		      //                      $this->SaveSessionVars();
                  }

	}


	function LoadLoginVars() {
		if ($GLOBALS["Systeme"]->getPostVars("login")!=""){
			//Ils sont dans les parametres Post
			$this->login = $GLOBALS["Systeme"]->getPostVars("login");
			$this->pass = md5($GLOBALS["Systeme"]->getPostVars("pass"));
			return true;
		}elseif ($GLOBALS["Systeme"]->getGetVars("login")!=""&&$GLOBALS["Systeme"]->getGetVars("passmd5")!=""&&$GLOBALS["Systeme"]->getGetVars("codeverif")!=""){
			$this->login = $GLOBALS["Systeme"]->getGetVars("login");
			$this->passmd5 = $GLOBALS["Systeme"]->getGetVars("passmd5");
			$this->codeverif = $GLOBALS["Systeme"]->getGetVars("codeverif");
			return true;
                }elseif ($_SESSION['login'] && $_SESSION['pass']){
                    	$this->login = $_SESSION['login'];
                        $this->pass = $_SESSION['pass'];
		}else{
			if ($this->login==""||$this->pass=="")	return false;
		}
	}

	//------------------------------------------------------------//
	//			CONNEXION			      //
	//------------------------------------------------------------//
	function getConnectionArray() {
		$Temp["Ip"]=$this->Ip;
		$Temp["Host"]=$this->Host;
		$Temp["Lang"]=$this->Lang;
		$Temp["Navigateur"]=$this->Navigateur;
		$Temp["Date"]=$this->Date;
		$Temp["Num"]=$this->Num;
		$Temp["SessId"]=$this->SessId;
		$Result[0]=$Temp;
		return $Result;
	}

	function GetConn() {
		//Recuperation de l adresse IP
		$this->Ip=getenv("REMOTE_ADDR");
		//Recuperation du nom de l hote
		//$this->Host=getenv("REMOTE_HOST");
		$this->Host=gethostbyaddr(getenv("REMOTE_ADDR"));
		//Langage de l hote
		$this->Navigateur=str_replace("/","",utf8_decode(getenv("HTTP_USER_AGENT")));
		$this->Navigateur=str_replace("'","",$this->Navigateur);
		$this->Navigateur=str_replace('"',"",$this->Navigateur);
		$this->Navigateur=str_replace("&","",$this->Navigateur);
		$this->Navigateur=str_replace(";","",$this->Navigateur);
		$this->Navigateur=str_replace("+","",$this->Navigateur);
		$this->Navigateur=str_replace("=","",$this->Navigateur);
		$this->Navigateur=str_replace("`","",$this->Navigateur);
		$this->Navigateur=str_replace("{","",$this->Navigateur);
		$this->Navigateur=str_replace("}","",$this->Navigateur);
		$this->Navigateur=str_replace("(","",$this->Navigateur);
		$this->Navigateur=str_replace(")","",$this->Navigateur);
		$this->Navigateur=str_replace("[","",$this->Navigateur);
		$this->Navigateur=str_replace("]","",$this->Navigateur);
		$this->Navigateur = htmlspecialchars($this->Navigateur);
		$this->Ref = getenv("HTTP_REFERER");
		//Langage de l hote
		$this->Langue=getenv("HTTP_ACCEPT_LANGUAGE");
		//DETECTION LANGUE NAVIGATEUR #TODO
		/*$Temp = $GLOBALS["Systeme"]->Conf->get("GENERAL::LANGUAGE");
		if (is_array($Temp)) foreach ($Temp as $T => $L){
			if (sizeof(explode($L["NAV"],$this->Langue)>1)){
				$GLOBALS["Systeme"]->DefaultLanguage = $L["TITLE"];
			}
		}*/
		//Generation den la date
		$this->Date = $this->initDate();
		//Test existance session
		if ($this->DetectCookies()||$_GET[PHP_SESSION_NAME]) {
			//On recupere le numero de session
			if ($_COOKIE[PHP_SESSION_NAME]!="")$this->SessId = $_COOKIE[PHP_SESSION_NAME];
			else $this->SessId = $_GET[PHP_SESSION_NAME];
		}
		//DETECTION AUTOMATIQUE
		$Temp = $GLOBALS["Systeme"]->Conf->get("GENERAL::LANGUAGE");
		foreach ($Temp as $Tit=>$Lang){
			 if ($Lang["NAV"]=="*"&&$LangueSite==""){
				$LangueSite=$Lang["TITLE"]; 
// 				echo "=> LANGUE DEFAUT".$Lang["TITLE"]."\r\n";
			}else {
				if (@preg_match("#".$Lang["NAV"]."#",$this->Langue,$out)){
//  					echo "=> CORRESPOND A LA LANGUE ".$Lang["TITLE"]."\r\n";
					$LangueSite = $Lang["TITLE"];
				}
			}
		}
		//RECUPERATION CONFIGURATION MANUELLE
		if (ADD_CONNECT){
			$query="Systeme/Connexion/Session=".$this->SessId."&Navigateur=".addslashes($this->Navigateur)."&Ip=".$this->Ip."&tmsEdit>".(time()-(CONNECT_TIMEOUT*60));
			$Results = $GLOBALS['Systeme']->Modules['Systeme']->callData($query);
			if (!empty($Results[0])){
				$this->Record = genericClass::createInstance("Systeme",$Results[0]);
				$LangueSite = $this->Record->LangueSite;
			}else $Out = false;
			$Out = true;
		}
		//DETECTION LANGUAGE
		if ($GLOBALS["Systeme"]->GetVars["SwitchLanguage"]!="") {
			//On verifie que l extension existe
			$Temp = $GLOBALS["Systeme"]->Conf->get("GENERAL::LANGUAGE");
			foreach ($Temp as $Tit=>$Lang) if ($Lang["TITLE"]==$GLOBALS["Systeme"]->GetVars["SwitchLanguage"]){
				$LangueSite = $GLOBALS["Systeme"]->GetVars["SwitchLanguage"];
			}
		}
		if ($LangueSite!="") $GLOBALS["Systeme"]->DefaultLanguage = $LangueSite;
		return $Out;
	}
	function AddConn()	{
	//Creation de la connexion
		if (ADD_CONNECT){
			if (!is_object($this->Record)){
				$this->Record = genericClass::createInstance("Systeme","Connexion");
				$this->Record->Set("Ip",$this->Ip);
				$this->Record->Set("Langue",$this->Langue);
				$this->Record->Set("Host",$this->Host);
				$this->Record->Set("LangueSite",$GLOBALS["Systeme"]->DefaultLanguage);
				$this->Record->Set("Navigateur",$this->Navigateur);
				$this->Record->Set("Referent",$this->Ref);
				$this->Record->Set("Session",$this->SessId);
				$this->Record->Save();

			}else{
				$this->Record->Set("LangueSite",$GLOBALS["Systeme"]->DefaultLanguage);
				$this->Record->Set("Session",$this->SessId);
				$this->Record->Save();
			}
		}
	}

	function InitConn() {
	//Initialisation de la connexion
		//Detection de l existence d une connexion
		if ($TempId!="") $this->Id=$TempId;
		//Ajout de la connexion a la base de donn� et stockage de l id
		else $this->Id=$this->AddConn();
	}
	function close () {
		if (ADD_CONNECT){
			//On supprime les connexions perimees
			$query="Systeme/Connexion/tmsEdit<".(time()-(CONNECT_TIMEOUT*60));
			$Results = $GLOBALS['Systeme']->Modules['Systeme']->callData($query);
			for ($i=0;$i<sizeof($Results);$i++) {
				$Connexion = genericClass::createInstance("Systeme","Connexion");
				$Connexion->Set("Id",$Results[$i]["Id"]);
				$Connexion->Delete();
			}
		}
	}

	//------------------------------------------------------------//
	//			USERS KOB-EYE			      //
	//------------------------------------------------------------//
	//Connexion d un utilisateur par un id ou par un tableau
	function initUser($Tab) {
		//Initialisation du genericClass
		if (is_object($Tab)) {
			//C est un objet
			$GLOBALS["Systeme"]->User = $Tab;
		}else{
			//C est un int
			$Result = $GLOBALS["Systeme"]->Modules["Systeme"]->callData("User/".$Tab);
			$User = genericClass::createInstance("Systeme",$Result[0]);
			$GLOBALS["Systeme"]->User = $User;
		}
		//Initialisation des groupes parents
		$Result = $GLOBALS["Systeme"]->Modules["Systeme"]->callData("Group/*/Group/User/".$GLOBALS["Systeme"]->User->Id);
// 		echo "INIT GROUP Group/*/Group/User/".$GLOBALS["Systeme"]->User->Id." \r\n";
// 		print_r($Result);
		//Initialisation des genereicClass pour les groupes
		if (is_array($Result))foreach ($Result as $g) {
			$T[] = genericClass::createInstance("Systeme",$g);
		}
// 		print_r($T);
		$GLOBALS["Systeme"]->User->Groups = $T;
		//Definition de la skin
		if (is_array($GLOBALS["Systeme"]->User->Groups))foreach ($GLOBALS["Systeme"]->User->Groups as $g) {
			if ($g->Skin!=""&&$g->Skin) {
				$SkinGroup = $g->Skin;
			}
		}
		if ($GLOBALS["Systeme"]->User->Skin==""||$GLOBALS["Systeme"]->User->Skin=="0") $GLOBALS["Systeme"]->User->Skin = ($SkinGroup!=""&&$SkinGroup)?$SkinGroup:MAIN_SKIN_NUM;
		//Initialisation des menus
		$Menus = $GLOBALS["Systeme"]->Modules["Systeme"]->callData("Systeme/User/".$GLOBALS["Systeme"]->User->Id."/Menu/*");
		if (is_array($GLOBALS["Systeme"]->User->Groups))foreach ($GLOBALS["Systeme"]->User->Groups as $g) {
			$Mt = $GLOBALS["Systeme"]->Modules["Systeme"]->callData("Systeme/Group/".$g->Id."/Menu/*");
			if (is_array($Mt)&&sizeof($Mt)) {
				//On concatene les menus dans un seul tableau
				foreach ($Mt as $M) {
					$Menus[] = $M;
				}
			}
		}
/*		echo "<ul>";
		foreach ($Menus as $K=>$M){
			echo "<li>".$K." - ".$M["Titre"]." - ".$M["Id"]."</li>";
		}
		echo "</ul>";*/
		//Maintenant on reorganise les menus afin qu ils soient exploitables
// 		echo " - ".sizeof($Menus)."  \r\n";
		$this->__autoload("Storproc");
		$Menus = StorProc::sortRecursivResult($Menus,"Menus");
// 		echo "<ul>";
		if (is_array($Menus))foreach ($Menus as $K=>$M) {
			$R[$K] = genericClass::createInstance("Systeme",$M);
// 			echo "<li>".$K." - ".$R[$K]->getFirstSearchOrder()."";
// 			echo "<ul>";
			if (is_array($M["Menus"]))foreach ($M["Menus"] as $K2=>$M2) {
				$R[$K]->Menus[$K2] = genericClass::createInstance("Systeme",$M2);
// 				echo "<li>".$K2." - ".$R[$K]->Menus[$K2]->getFirstSearchOrder()."</li>";
				if (is_array($M2["Menus"]))foreach ($M2["Menus"] as $K3=>$M3) {
					$R[$K]->Menus[$K2]->Menus[$K3] = genericClass::createInstance("Systeme",$M3);
	// 				echo "<li>".$K2." - ".$R[$K]->Menus[$K2]->getFirstSearchOrder()."</li>";
				}
			}
// 			echo "</ul></li>";
		}
// 		echo "</ul>";
		$GLOBALS["Systeme"]->User->Menus = $R;
	}

	function DetectUser() {
		//Detection de l utilisateur
		if (!is_null($this->login)) {
			if (!is_null($this->passmd5)&&!is_null($this->codeverif)){
				//CAS LOGIN JETON MD5
				$Result = $GLOBALS["Systeme"]->Modules["Systeme"]->callData("User/Login=".$this->login."&Pass=".$this->passmd5."&CodeVerif=".$this->codeverif);
				$GLOBALS["Systeme"]->Log->log("DETECT USER >> PASSMD5 GET ".$Result[0]["Id"]);
				if (!is_array($Result[0])) return false;
				$User = genericClass::createInstance("Systeme",$Result[0]);
				$User->Save();
			}elseif (is_object($GLOBALS["Systeme"]->User) && !$GLOBALS["Systeme"]->User->Public){ 
				$GLOBALS["Systeme"]->Log->log("DETECT USER >> SESSION CACHE ".$GLOBALS["Systeme"]->User->Id);
				//CAS RECUP CACHE SESSION
				$User = $GLOBALS["Systeme"]->User;
				//$Result = $GLOBALS["Systeme"]->Modules["Systeme"]->callData("User/Login=".$User->Login."&Pass=".$User->Pass."&CodeVerif=".$User->CodeVerif);
				//if (!is_array($Result[0])) return false;
				//else 
				  return true;
			}
			else{
			  //				$GLOBALS["Systeme"]->Log->log("DETECT USER >> POST Login=".$this->login);
				//CAS LOGIN PASS POST
			        
				$Result = $GLOBALS["Systeme"]->Modules["Systeme"]->callData("User/Login=".$this->login."&Pass=".$this->pass);

				if (!is_array($Result[0])) return false;
				$User = genericClass::createInstance("Systeme",$Result[0]);
			}
			//On verifie le mot de passe dans  la classe generique
			if ($User->Actif) {
				$this->initUser($User);
				return true;
			}else{
				//OK donc il existe une session mais les dientifiants de connexion sont erron�s donc il faut detruire la session
				$GLOBALS["Systeme"]->Error->sendErrorMsg(100);
				$this->destroyPrivateSession();
			}
		}
		return false;
	}

	function initDefaultUser() {
		$GLOBALS["Systeme"]->User = "";
		//$Query,$recurs="",$Ofst="",$Limit="",$OrderType="",$OrderVar="",$Selection=""
		$Result = $GLOBALS["Systeme"]->Modules["Systeme"]->callData("User/Domaine=".$_SERVER["HTTP_HOST"],false,0,1,"ASC","Id","m.Id,m.CodeVerif");
		if (is_array($Result[0])) {
			//On verifie quil nexiste pas deja un fichier cache pour lutilisateur
			$User = genericClass::createInstance("Systeme",$Result[0]);
			if ($User->Id>-1&&file_exists("Home/".$User->Id."/.UserCache"&&USER_CACHE)){
				$GLOBALS["Systeme"]->Log->log("DETECT USER >> LOAD CACHE DEFAULT USER DOMAINE ".$_SERVER["HTTP_HOST"]."  ".$User->Id);
				$GLOBALS["Systeme"]->User = unserialize(file_get_contents("Home/".$User->Id."/.UserCache"));
				if ($Result[0]["CodeVerif"]!=$GLOBALS["Systeme"]->User->CodeVerif&&$Result[0]["CodeVerif"]!="")$GLOBALS["Systeme"]->User = "";
			}
			if (!is_object($GLOBALS["Systeme"]->User)){
				$GLOBALS["Systeme"]->Log->log("DETECT USER >> INIT DEFAULT USER DOMAINE ".$_SERVER["HTTP_HOST"]."  ".$User->Id);
				$this->initUser($User->Id);
				//On genere le cache
				if (USER_CACHE)$this->writeCacheFile(serialize($GLOBALS["Systeme"]->User),"Home/".$User->Id."",".UserCache");
			}
		}else{
			if (file_exists("Home/".MAIN_USER_NUM."/.UserCache")){
				$GLOBALS["Systeme"]->Log->log("DETECT USER >> LOAD CACHE DEFAULT USER MAIN_USER_NUM ".MAIN_USER_NUM);
				$GLOBALS["Systeme"]->User = unserialize(file_get_contents("Home/".MAIN_USER_NUM."/.UserCache"));
				if ($Result[0]["CodeVerif"]->CodeVerif!=$GLOBALS["Systeme"]->User->CodeVerif&&$Result[0]["CodeVerif"]!="")$GLOBALS["Systeme"]->User = "";
			}
			if (!is_object($GLOBALS["Systeme"]->User)){
				$GLOBALS["Systeme"]->Log->log("DETECT USER >> INIT DEFAULT USER MAIN_USER_NUM ".MAIN_USER_NUM);
				$this->initUser(MAIN_USER_NUM);
				//On genere le cache
				$this->writeCacheFile(serialize($GLOBALS["Systeme"]->User),"Home/".$Result[0]["Id"]."",".UserCache");
			}
		}
		$GLOBALS["Systeme"]->User->Public = 1;
	}

	function writeCacheFile($Data,$Url,$Name) {
		$GLOBALS["Systeme"]->Log->log("CACHE >> WRITE CACHE  ".$Url."/".$Name);
		if (!$File=fopen ($Url."/".$Name,"w")){
			$this->mk_dir($Url);
		}
		fwrite($File,$Data);
		fclose($File);
	}

	function isLogged() {
		if ($this->SessId!="") return true;
		else return false;
	}

	function DisconnectInPlace(){
		$GLOBALS["Systeme"]->isLogged=0;
		session_start();
		$_SESSION = array();
		if (isset($_COOKIE[session_name()])) {
			setcookie(session_name(), '', time()-42000, '/');
		}
		session_destroy();
		setcookie (PHP_SESSION_NAME, "", time()-60000);
		//SUppression de la connexion
		$this->Record->Delete();
		header("Location: ".$this->Ref);
		return true;
	}


	function Disconnect() {
		$GLOBALS["Systeme"]->isLogged=0;
		session_start();
		$_SESSION = array();
		if (isset($_COOKIE[session_name()])) {
			setcookie(session_name(), '', time()-42000, '/');
		}
		session_destroy();
		setcookie (PHP_SESSION_NAME, "", time()-60000);
		if (ADD_CONNECT)$this->Record->Delete();
		header("Location: http://".$_SERVER["HTTP_HOST"]."/");
		return true;
	}

	//------------------------------------------------------------//
	//			UTILS				      //
	//------------------------------------------------------------//

	function initDate() {
	//Fonction d initialisation de la date
		$TempDate=date("YmdHis");
		return $TempDate;
	}

	function mk_dir($path, $rights = 0777){
		$folder_path = array($path);
		while(!@is_dir(dirname(end($folder_path)))
			&& dirname(end($folder_path)) != '/'
			&& dirname(end($folder_path)) != '.'
			&& dirname(end($folder_path)) != '')
		array_push($folder_path, dirname(end($folder_path)));
		while($parent_folder_path = array_pop($folder_path)){
			if(@mkdir($parent_folder_path, $rights))
			//user_error("Can't create folder \"$parent_folder_path\".");
			chmod ($parent_folder_path,$rights);
		}
	}
	



}




?>
